<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="utf-8" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />

<xsl:template match="/">
<html lang='ru'><head><title>Download Queue</title>
<link rel='stylesheet' type='text/css' href='olive.css'/><script src='functions.js'></script>
</head>
<body onload='if (typeof add_init == "function") add_init();'><xsl:apply-templates select="GQ"/></body></html>
</xsl:template>

<xsl:template match="GQ">
<h3>Очередь</h3>
<form method='get' action='add.cgi' id='url' >
<input type='text' name='furl' length='250' form='url' /><input type='submit' value='Add' form='url' />
</form>
<br/><input type='button' onclick='action.document.location="check.pl"' value='check urls' />
<xsl:apply-templates select="Question"/>
<xsl:apply-templates select="queue"/>
</xsl:template>

<xsl:template match="queue">
<table border='1'>
<thead><xsl:apply-templates select="el[1]" mode="th" /></thead>
<thead><xsl:apply-templates select="el[1]" mode="tf" /></thead>
<tbody><xsl:apply-templates select="el"/></tbody>
</table>
<iframe name='action' height='80' border='0' src='void.htm'>iFrame not supported!</iframe>

</xsl:template>

<xsl:template match="Question">
    <p>You ask to add url:
    <b><xsl:value-of select="url"/></b>
    <xsl:if test="size"><br/>Size: <b><xsl:value-of select="size"/></b></xsl:if>
    </p>
</xsl:template>

<xsl:template match="el" mode="th">
<tr class="head">
    <xsl:for-each select="@*">
    <th><xsl:value-of select="name()"/></th>
    </xsl:for-each>
</tr>
</xsl:template>

<xsl:template match="el" mode="tf">
<xsl:variable name="total" select="sum(//@size)" />
<tr class="tail">
    <xsl:for-each select="@*">
    <th><xsl:choose>
	<xsl:when test="name()='size'"><xsl:value-of select="$total"/></xsl:when>
	<xsl:when test="name()='id'"><xsl:value-of select="count(//el)"/></xsl:when>
	<xsl:when test="name()='url'"><xsl:value-of select="concat(format-number($total div 1048576,'0.###'),' MB, ', format-number($total div 1800000, '0.#'),' kB/s, ', format-number($total div 5242880, '0.#'),' rub.')"/></xsl:when>

<!-- %.1f kbps, %.2f руб)\n",$st*8/4/60/60/1000,$sm*.2; -->
	
    </xsl:choose></th>
    </xsl:for-each>
</tr>
</xsl:template>

<xsl:template match="el">
<!-- <xsl:sort /> -->
<tr>
    <xsl:for-each select="@*">
    <td id='{name()}'><xsl:choose>
	<xsl:when test="name()='id'">
	    <a href='cancel.cgi?{.}' title="Cancel!" target='action'><xsl:value-of select="." /></a>
	</xsl:when>
	<xsl:when test="name()='prio'">

	<select name='prio' title='Priority 10-max, 0-min' onchange='add_go(this,{../@id});'>

	<option class='cyan'>
	    <xsl:if test=". &lt; 0"><xsl:attribute name="selected"/></xsl:if>
	    <xsl:value-of select="-1"/> 
	</option>

	<option class='white'>
	    <xsl:if test=". = 0"><xsl:attribute name="selected"/></xsl:if>
	    <xsl:value-of select="0"/> 
	</option>

	<option class='pink'>
	    <xsl:if test=". = 5"><xsl:attribute name="selected"/></xsl:if>
	    <xsl:value-of select="5"/>
	</option>

	<option class='red'>
	    <xsl:if test=". = 10"><xsl:attribute name="selected"/></xsl:if>
	    <xsl:value-of select="10"/>
	</option>

	</select>

	</xsl:when>
	<xsl:when test="name()='size'"><xsl:attribute name="align">right</xsl:attribute>
	<xsl:if test=". &gt; 7000000"><xsl:attribute name="class">pink</xsl:attribute></xsl:if>
	    <xsl:value-of select="." />
	</xsl:when>
	
	<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
    </xsl:choose></td>
    </xsl:for-each>
</tr>
</xsl:template>

</xsl:stylesheet>
